define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template','/assets/addons/kuyou/layui/layui.js'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function () {
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    var myChart = Echarts.init(document.getElementById('echart'), 'walden');
                    myChart.resize();

                    var myCharts = Echarts.init(document.getElementById('echart2'), 'walden');
                    myCharts.resize();
                }, 0);
            });

            $(document).on("click", ".btn_chart", function () {
                var id = $(this).data('id');
                $('.btn_chart').removeClass('active');
                $(this).addClass('active');
                getChart(id)
            });
            getChart(1);
            function getChart(types) {
                $.ajax({
                    type : 'POST',
                    url : 'kuyou/datainfo/index',
                    data:{
                        'types':types
                    },
                    success : function(res){
                        if(types<3){
                            $('#echart2').hide();$('#echart').show();
                            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
                            var option = {
                                title: {
                                    text: '',
                                    subtext: ''
                                },
                                color: [
                                    "#18d1b1",
                                    "#3fb1e3",
                                    "#626c91",
                                    "#a0a7e6",
                                    "#c4ebad",
                                    "#96dee8"
                                ],
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: [res.legend]
                                },
                                toolbox: {
                                    show: false,
                                    feature: {
                                        magicType: {show: true, type: ['stack', 'tiled']},
                                        saveAsImage: {show: true}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: res.column
                                },
                                yAxis: {},
                                grid: [{
                                    left: 'left',
                                    top: 'top',
                                    right: '10',
                                    bottom: 30
                                }],
                                series: [{
                                    name: res.legend,
                                    type: 'line',
                                    smooth: true,
                                    areaStyle: {
                                        normal: {}
                                    },
                                    lineStyle: {
                                        normal: {
                                            width: 1.5
                                        }
                                    },
                                    data: res.data
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            myChart.setOption(option);
                            window.addEventListener("resize", function () {
                                myChart.resize();
                            });
                        }else{
                            $('#echart').hide();$('#echart2').show();
                            var myChart = Echarts.init(document.getElementById('echart2'), 'walden');
                            option = {
                                title: {
                                    text: res.title,
                                    left: 'center'
                                },
                                tooltip: {
                                    trigger: 'item'
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left'
                                },
                                series: [
                                    {
                                        name: res.legend,
                                        type: 'pie',
                                        radius: '50%',
                                        data: res.data,
                                        emphasis: {
                                            itemStyle: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                                            }
                                        }
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            myChart.setOption(option);
                            window.addEventListener("resize", function () {
                                myChart.resize();
                            });
                        }
                    }
                });
            }
        },
        datainfo:function(){
            var checkTime = function (i) {
                if (i < 10) {
                    i = "0" + i;
                }
                return i;
            };
            var showtime = function () {
                var nowdate = new Date();
                var h = nowdate.getHours(),
                    m = nowdate.getMinutes(),
                    s = nowdate.getSeconds(),
                    h = checkTime(h),
                    m = checkTime(m),
                    s = checkTime(s);
                return h +":" + m + ":" + s;
            };
            var div = document.getElementById("showtime");
            setInterval (function() {
                div.innerHTML = showtime();
            }, 1000);  //反复执行函数

            //饼图
            function p_left2_chart(data,unit) {
                var p_left2_chart = Echarts.init(document.getElementById('p_left2_chart'), 'walden');
                var option = {
                    tooltip: {
                        trigger: "item",
                        formatter: "{b} : ({d}%)</br>销售额 : {c}"+unit,
                    },
                    legend: {
                        orient: 'horizontal',
                        left: 'center',
                        bottom:'bottom',
                        textStyle:{
                            color:"#ffffff"
                        }
                    },
                    // color: ["#5AD8A6", "#5B8FF9", "#F6BD16", "#E8684A", "#00ec69"],
                    series: [
                        {
                            name: __('sales volume'),
                            type: 'pie',
                            radius: '50%',
                            data: data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                p_left2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_left2_chart.resize();
                });
            }
            //客户增长趋势
            function p_left3_chart(data,unit) {
                var p_left3_chart = Echarts.init(document.getElementById('p_left3_chart'), 'walden');
                var option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    // legend: {
                    //     data: [__('Total number of customers'),__('Customer growth volume')]
                    // },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        splitLine:{show:false},
                        boundaryGap: true,
                        data: data.xAxis,
                        axisLabel:{
                            textStyle:{
                                color:'#AEBDFF'
                            }
                        }
                    },
                    yAxis: {
                        type: 'value',
                        splitLine:{show:false},
                        axisLabel:{
                            textStyle:{
                                color:'#AEBDFF'
                            }
                        }
                    },
                    series: [
                        {
                            name: __('Total number of customers'),
                            type: 'line',
                            stack: __('individual'),
                            data: data.series.customers_num,
                            itemStyle: {
                                normal: {
                                    color: '#F62B2B', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#F62B2B' //改变折线颜色
                                    }
                                }
                            },
                        },
                        {
                            name: __('Customer growth volume'),
                            type: 'line',
                            stack: __('individual'),
                            data: data.series.customers,
                            itemStyle: {
                                normal: {
                                    color: '#09F197', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#09F197' //改变折线颜色
                                    }
                                }
                            },
                        },
                    ]
                };
                p_left3_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_left3_chart.resize();
                });
            }

            function p_center1_chart(data,unit) {
                var p_center1_chart = Echarts.init(document.getElementById('p_center1_chart'), 'walden');
                option = {
                    // tooltip: {
                    //     trigger: 'axis'
                    // },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        },
                        formatter: function (params) {
                            let html=params[0].name+"<br>";
                            for(let i=0;i<params.length;i++){
                                html+='<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'
                                if(params[i].seriesName==__('sales volume')){
                                    html+=params[i].seriesName+":"+params[i].value+""+unit+"<br>";
                                }
                                if(params[i].seriesName==__('Number of sales transactions')){
                                    html+=params[i].seriesName+":"+params[i].value+"笔<br>";
                                }
                            }
                            return html;
                        }
                    },
                    // legend: {
                    //     data: [__('sales volume'), __('Number of sales transactions')]
                    // },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        splitLine:{show:false},
                        boundaryGap: true,
                        data: data.xAxis,
                    },
                    yAxis: [
                        {
                            type: 'value',
                            name: unit,
                            //坐标轴最大值、最小值、强制设置数据的步长间隔
                            // interval: 1000,
                            axisLabel: {
                                //y轴上带的单位
                                formatter: '{value}'
                            },
                            //轴线
                            axisLine: {
                                show: true
                            },
                            //分割线
                            splitLine: {
                                show: false
                            }
                        },
                        {
                            type: 'value',
                            name: __('pen'),
                            axisLabel: {
                                formatter: '{value}'
                            },
                            //轴线
                            axisLine: {
                                show: true
                            },
                            //分割线
                            splitLine: {
                                show: false
                            }

                        }
                    ],
                    series: [
                        {
                            name: __('sales volume'),
                            type: 'line',
                            yAxisIndex: 0,
                            data: data.series.num,
                        }, {
                            name: __('Number of sales transactions'),
                            type: 'line',
                            yAxisIndex: 1,
                            data: data.series.count,
                            itemStyle: {
                                normal: {
                                    color: '#09F197', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#09F197' //改变折线颜色
                                    }
                                }
                            },
                        }
                    ]
                };
                p_center1_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_center1_chart.resize();
                });
            }
            function p_center2_chart(data,unit) {
                var p_center2_chart = Echarts.init(document.getElementById('p_center2_chart'), 'walden');
                var option = {
                    // color : [ '#09F197', '#4e2b63' ],
                    // legend : [ {
                    //     itemWidth : 10,
                    //     itemHeight : 10,
                    //     align : 'left',
                    //     right : '45',
                    //     textStyle : {
                    //         fontSize : 10,
                    //         color : '#cccece',
                    //     },
                    //     itemStyle : {
                    //         borderColor : '#04a3a7',
                    //         borderWidth : 1
                    //     },
                    //
                    //     data : [ __('purchase') ]
                    // },
                    //     {
                    //         itemWidth : 10,
                    //         itemHeight : 10,
                    //         align : 'left',
                    //         right : 10,
                    //         textStyle : {
                    //             fontSize : 10,
                    //             color : '#cccece',
                    //         },
                    //         itemStyle : {
                    //             borderColor : '#b527ae',
                    //             borderWidth : 1
                    //         },
                    //
                    //         data : [ __('sale') ]
                    //     },
                    // ],

                    grid : {
                        left : '15',
                        right : '15',
                        bottom : '5',
                        top: '20',
                        containLabel : true
                    },

                    xAxis : [
                        {
                            type : 'value',
                            // max : 100,
                            // min : -100,
                            splitLine : {
                                show : false
                            },
                            axisLine : {
                                show : true
                            },
                            axisTick : {
                                show : false
                            },
                            boundaryGap: ['5%', '5%'],
                            axisLabel : {
                                fontSize:10,
                                color : '#AEBDFF',
                                show : true,
                                formatter : function(value, index) {
                                    var texts = [ value, '' ];

                                    if (value < 0) {
                                        texts = [ -value, '' ];
                                    }

                                    if (texts.join('') === '0') {
                                        return 0;
                                    }
                                    return texts.join('');
                                }
                            }
                        }
                    ],

                    yAxis : [
                        {
                            type: 'category',
                            splitLine:{show:false},
                            axisLine : {
                                show : true
                            },
                            axisTick : {
                                show : false
                            },
                            data: data.yAxis,
                            axisLabel:{
                                textStyle:{
                                    color:'#AEBDFF'
                                },
                            }
                        }
                    ],
                    series : [
                        //为了让两边的条形图在中间线分开设置的辅助数据
                        {
                            name : __('auxiliary'),
                            type : 'bar',
                            stack : __('total'),
                            itemStyle : {
                                normal : {
                                    barBorderColor : 'rgba(0,0,0,0)',
                                    color : 'rgba(0,0,0,0)'
                                }
                            },
                            data : [ -1, -1, -1, -1, -1, -1 ]
                        },

                        {
                            name : __('purchase'),
                            type : 'bar',
                            stack : __('total'),
                            //barCategoryGap : '60%',
                            barWidth : 10,//柱图宽度
                            label : {
                                normal : {
                                    show : true,
                                    formatter: function (params) {
                                        var num = params.value;
                                        num = -num;
                                        return num;
                                    },
                                    position : 'left',
                                    color: '#cccece'
                                }
                            },
                            itemStyle: {
                                //通常情况下：
                                normal: {
                                    barBorderRadius: 20,
                                    color: new Echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                        offset: 0,
                                        color: '#099b58'
                                    }, {
                                        offset: 1,
                                        color: '#00FFC8'
                                    }]),
                                    shadowColor: 'rgba(0, 0, 0, 0.4)',
                                    shadowBlur: 20
                                },
                            },
                            data:data.series.purchase
                        },

                        {
                            name : __('auxiliary'),
                            type : 'bar',
                            stack : __('total'),
                            itemStyle : {
                                normal : {
                                    barBorderColor : 'rgba(0,0,0,0)',
                                    color : 'rgba(0,0,0,0)'
                                }
                            },
                            data : [ 1, 1, 1, 1, 1, 1 ]
                        },
                        {
                            name : __('sale'),
                            type : 'bar',
                            stack : __('total'),
                            barWidth : 10,//柱图宽度
                            label : {
                                normal : {
                                    show : true,
                                    formatter: function (params) {
                                        var num = params.value;
                                        return num;
                                    },
                                    position : 'right',
                                    color: '#cccece'
                                }
                            },
                            itemStyle: {
                                normal: {
                                    barBorderRadius: 20,
                                    color: new Echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                        offset: 0,
                                        color: '#13EFFA'
                                    }, {
                                        offset: 1,
                                        color: '#078a9b'
                                    }]),
                                    shadowColor: 'rgba(0, 0, 0, 0.4)',
                                    shadowBlur: 20
                                },
                            },
                            data:data.series.sales
                        }
                    ]
                };
                p_center2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_center2_chart.resize();
                });
            }

            function p_right2_chart(data,unit) {
                var p_right2_chart = Echarts.init(document.getElementById('p_right2_chart'), 'walden');
                option = {
                    grid: {
                        left: '3%',
                        right: '10%',
                        bottom: '5%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        splitLine: {show: false},
                        axisLabel: {show: false},//坐标轴刻度标签
                        axisTick: {show: false},//坐标轴刻度
                        axisLine: {show: false},//坐标轴轴线
                    },
                    yAxis: {
                        type: 'category',
                        splitLine: {show: false},
                        axisTick: {show: false},
                        axisLine: {show: false},
                        axisLabel: {
                            color: '#fff',
                            fontSize: 14
                        },
                        data: data.yAxis
                    },
                    series: [
                        {
                            name: unit,//系列名称
                            type: 'bar',//柱状、条形图
                            barWidth: 19,//柱条的宽度,默认自适应
                            data: data.series.data,//系列中数据内容数组
                            label: { //图形上的文本标签
                                show: true,
                                // position: 'right',//标签的位置
                                // offset: [-60,1],  //标签文字的偏移，此处表示向上偏移40
                                formatter: '{c}{a}',//标签内容格式器 {a}-系列名,{b}-数据名,{c}-数据值
                                color: '#fff',//标签字体颜色
                                fontSize: 14  //标签字号
                            },
                            itemStyle: {//图形样式
                                normal: {
                                    barBorderRadius: 10,//柱条圆角半径,单位px.
                                    color: "#0272FC"
                                }
                            },
                            zlevel:1
                        },
                        {
                            name: __('Progress bar background'),
                            type: 'bar',
                            barGap: '-100%',
                            barWidth: 19,
                            data: data.series.max,
                            color: '#1d359b',//柱条颜色
                            label: { //图形上的文本标签
                                show: true,
                                position: 'right',//标签的位置
                                // offset: [-40,0],  //标签文字的偏移，此处表示向上偏移40
                                // formatter: '{b}',//标签内容格式器 {a}-系列名,{b}-数据名,{c}-数据值
                                formatter: function (params) {
                                    return data.series.per[params.name]+'%';
                                },
                                color: '#fff',//标签字体颜色
                                fontSize: 14  //标签字号
                            },
                            itemStyle: {
                                normal: {
                                    barBorderRadius: 10
                                }
                            }
                        }
                    ]
                };
                p_right2_chart.setOption(option);
                window.addEventListener("resize", function () {
                    p_right2_chart.resize();
                });
            }

            getChart(1);
            function getChart(types) {
                $.ajax({
                    type : 'POST',
                    url : 'kuyou/datainfo/datainfo',
                    data:{
                        'types':types
                    },
                    success : function(res){
                        var sales_money = res.sales_money;
                        var html = '';
                        $(sales_money).each(function (k,v) {
                            if(v===','){
                                html += '<small><span>,</span></small>';
                            }else{
                                html += '<span>'+v+'</span>';
                            }
                        });
                        $('#con_box').html(html);
                        $('.unit_value').html('（'+res.unit+'）');

                        p_left2_chart(res.left2_chart,res.unit);
                        p_left3_chart(res.left3_chart,res.unit);
                        p_center1_chart(res.center1_chart,res.unit);
                        p_center2_chart(res.center2_chart,res.unit);
                        p_right2_chart(res.right2_chart,res.unit);
                        var ht = '';
                        $(res.sale_list).each(function (k,v) {
                            var ks = k-(-1);
                            ht += '<tr><td><div class="sort_box"><span class="sort_number">'+ks+'</span></div></td><td>'+v.goods_code+'</td><td>'+v.goods_name+'</td><td>'+v.money_tax_price+'</td></tr>';
                        });
                        $('#phList').html(ht);
                    }
                });
            }
        },
        datainfos: function () {
            $(document).on("click", ".btn-refresh", function () {
            });
            var checkTime = function (i) {
                if (i < 10) {
                    i = "0" + i;
                }
                return i;
            };
            var showtime = function () {
                var nowdate = new Date();
                var h = nowdate.getHours(),
                    m = nowdate.getMinutes(),
                    s = nowdate.getSeconds(),
                    h = checkTime(h),
                    m = checkTime(m),
                    s = checkTime(s);
                return h +":" + m + ":" + s;
            };
            var div = document.getElementById("showtime");
            setInterval (function() {
                div.innerHTML = showtime();
            }, 1000);  //反复执行函数

            //加工单完成
            function jgdwc(e=0) {
                var chart_jgdwc = Echarts.init(document.getElementById('chart_jgdwc'), 'walden');
                option = {
                    title: {
                        show: true,
                        text: e + "%",
                        x: "center",
                        y: "center",// 通过x,y将标题(进度)定位在圆环中心
                        textStyle: {
                            fontSize: "25",
                            color: "white",
                            fontWeight: "400",
                            fontFamily: "DINPro, DINPro-Regular",
                        },
                    },
                    tooltip: {
                        trigger: "item",
                        formatter: "{d}%",
                        show: false,
                    },
                    legend: {
                        orient: "vertical",
                        x: "left",
                        show: false,
                    },
                    series: {
                        name: "",
                        type: "pie",
                        radius: ["65%", "75%"],
                        avoidLabelOverlap: true,
                        hoverAnimation: false,
                        label: {
                            normal: {
                                show: false,
                                position: "center",
                            },
                            emphasis: {
                                show: false,
                            },
                        },
                        labelLine: {
                            normal: {
                                show: false,
                            },
                        },
                        data: [
                            {
                                value: e,
                                name: "",
                                itemStyle: {
                                    color: "#09F197",
                                },
                            },
                            {
                                value: 100 - e,
                                name: "",
                                itemStyle: {
                                    color: "#2345DB",//透明色，也可以设置把其他颜色
                                },
                            },
                        ],
                    },
                }
                chart_jgdwc.setOption(option);
                window.addEventListener("resize", function () {
                    chart_jgdwc.resize();
                });
            }

            //加工单不良
            function jgdbl(e=0) {
                var chart_jgdbl = Echarts.init(document.getElementById('chart_jgdbl'), 'walden');
                option = {
                    title: {
                        show: true,
                        text: e + "%",
                        x: "center",
                        y: "center",// 通过x,y将标题(进度)定位在圆环中心
                        textStyle: {
                            fontSize: "25",
                            color: "white",
                            fontWeight: "400",
                            fontFamily: "DINPro, DINPro-Regular",
                        },
                    },
                    tooltip: {
                        trigger: "item",
                        formatter: "{d}%",
                        show: false,
                    },
                    legend: {
                        orient: "vertical",
                        x: "left",
                        show: false,
                    },
                    series: {
                        name: "",
                        type: "pie",
                        radius: ["65%", "75%"],
                        avoidLabelOverlap: true,
                        hoverAnimation: false,
                        label: {
                            normal: {
                                show: false,
                                position: "center",
                            },
                            emphasis: {
                                show: false,
                            },
                        },
                        labelLine: {
                            normal: {
                                show: false,
                            },
                        },
                        data: [
                            {
                                value: 100 - e,
                                name: "",
                                itemStyle: {
                                    color: "#2345DB",//透明色，也可以设置把其他颜色
                                },
                            },
                            {
                                value: e,
                                name: "",
                                itemStyle: {
                                    color: "#F62B2B",
                                },
                            },
                        ],
                    },
                }
                chart_jgdbl.setOption(option);
                window.addEventListener("resize", function () {
                    chart_jgdbl.resize();
                });
            }

            //委外加工单完成
            function wwjgdwc(e=0) {
                var chart_wwjgdwc = Echarts.init(document.getElementById('chart_wwjgdwc'), 'walden');
                option = {
                    title: {
                        show: true,
                        text: e + "%",
                        x: "center",
                        y: "center",// 通过x,y将标题(进度)定位在圆环中心
                        textStyle: {
                            fontSize: "25",
                            color: "white",
                            fontWeight: "400",
                            fontFamily: "DINPro, DINPro-Regular",
                        },
                    },
                    tooltip: {
                        trigger: "item",
                        formatter: "{d}%",
                        show: false,
                    },
                    legend: {
                        orient: "vertical",
                        x: "left",
                        show: false,
                    },
                    series: {
                        name: "",
                        type: "pie",
                        radius: ["65%", "75%"],
                        avoidLabelOverlap: true,
                        hoverAnimation: false,
                        label: {
                            normal: {
                                show: false,
                                position: "center",
                            },
                            emphasis: {
                                show: false,
                            },
                        },
                        labelLine: {
                            normal: {
                                show: false,
                            },
                        },
                        data: [
                            {
                                value: e,
                                name: "",
                                itemStyle: {
                                    color: "#09F197",
                                },
                            },
                            {
                                value: 100 - e,
                                name: "",
                                itemStyle: {
                                    color: "#2345DB",//透明色，也可以设置把其他颜色
                                },
                            },
                        ],
                    },
                }
                chart_wwjgdwc.setOption(option);
                window.addEventListener("resize", function () {
                    chart_wwjgdwc.resize();
                });
            }

            //委外加工单不良
            function wwjgdbl(e=0) {
                var chart_wwjgdbl = Echarts.init(document.getElementById('chart_wwjgdbl'), 'walden');
                option = {
                    title: {
                        show: true,
                        text: e + "%",
                        x: "center",
                        y: "center",// 通过x,y将标题(进度)定位在圆环中心
                        textStyle: {
                            fontSize: "25",
                            color: "white",
                            fontWeight: "400",
                            fontFamily: "DINPro, DINPro-Regular",
                        },
                    },
                    tooltip: {
                        trigger: "item",
                        formatter: "{d}%",
                        show: false,
                    },
                    legend: {
                        orient: "vertical",
                        x: "left",
                        show: false,
                    },
                    series: {
                        name: "",
                        type: "pie",
                        radius: ["65%", "75%"],
                        avoidLabelOverlap: true,
                        hoverAnimation: false,
                        label: {
                            normal: {
                                show: false,
                                position: "center",
                            },
                            emphasis: {
                                show: false,
                            },
                        },
                        labelLine: {
                            normal: {
                                show: false,
                            },
                        },
                        data: [
                            {
                                value: 100 - e,
                                name: "",
                                itemStyle: {
                                    color: "#2345DB",//透明色，也可以设置把其他颜色
                                },
                            },
                            {
                                value: e,
                                name: "",
                                itemStyle: {
                                    color: "#F62B2B",
                                },
                            },
                        ],
                    },
                };
                chart_wwjgdbl.setOption(option);
                window.addEventListener("resize", function () {
                    chart_wwjgdbl.resize();
                });
            }

            //折线图
            function zxttj(xAxis,series) {
                var jrsjdb = Echarts.init(document.getElementById('jrsjdb'), 'walden');
                var option = {
                    // title: {
                    //     text: __('Stacking Line Chart')
                    // },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
                        data: [__('Total production quantity'),__('Total qualified quantity'),__('Unqualified number')]
                    },

                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        splitLine:{show:false},
                        boundaryGap: false,
                        data: xAxis,
                        axisLabel:{
                            textStyle:{
                                color:'#AEBDFF'
                            }
                        }
                    },
                    yAxis: {
                        type: 'value',
                        splitLine:{show:false},
                        axisLabel:{
                            textStyle:{
                                color:'#AEBDFF'
                            }
                        }
                    },
                    series: [
                        {
                            name: __('Total production quantity'),
                            type: 'line',
                            stack: __('individual'),
                            data: series.all_number,
                            showSymbol: false,//隐藏所有数据点
                            itemStyle: {
                                normal: {
                                    color: '#F62B2B', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#F62B2B' //改变折线颜色
                                    }
                                }
                            },
                        },
                        {
                            name: __('Total qualified quantity'),
                            type: 'line',
                            stack: __('individual'),
                            data: series.number,
                            showSymbol: false,//隐藏所有数据点
                            itemStyle: {
                                normal: {
                                    color: '#09F197', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#09F197' //改变折线颜色
                                    }
                                }
                            },
                        },
                        {
                            name: __('Unqualified number'),
                            type: 'line',
                            stack: __('individual'),
                            data: series.bad_number,
                            showSymbol: false,//隐藏所有数据点
                            itemStyle: {
                                normal: {
                                    color: '#08DBF4', //改变折线点的颜色
                                    lineStyle: {
                                        color: '#08DBF4' //改变折线颜色
                                    }
                                }
                            },
                        },
                    ]
                };
                jrsjdb.setOption(option);
                window.addEventListener("resize", function () {
                    jrsjdb.resize();
                });
            }

            getChart(1);
            function getChart(types) {
                $.ajax({
                    type : 'POST',
                    url : 'kuyou/datainfo/datainfos',
                    data:{
                        'types':types
                    },
                    success : function(res){
                        if(res['countArr']!=undefined){
                            var countArr = res['countArr'];
                            $('.zsl').html(countArr.count.need_number);
                            $('.wcsl').html(countArr.count.number);
                            $('.wcl').html(countArr.count.number_pr);
                            $('.bll').html(countArr.count.bad_number_pr);
                            $('.rgsl').html(countArr.count.works);
                            $('.rgys').html(countArr.count.hours);

                            $('.jrzs').html(countArr.jgd.need_number);
                            $('.jrrg').html(countArr.jgd.works);
                            $('.jrwc').html(countArr.jgd.number);
                            $('.jrys').html(countArr.jgd.work_hours);
                            jgdwc(countArr.jgd.number_pr);
                            jgdbl(countArr.jgd.bad_number_pr);

                            $('.jrwwzs').html(countArr.wwjgd.need_number);
                            $('.jrwwrg').html(countArr.wwjgd.works);
                            $('.jrwwwc').html(countArr.wwjgd.number);
                            $('.jrwwys').html(countArr.wwjgd.work_hours);
                            wwjgdwc(countArr.wwjgd.number_pr);
                            wwjgdbl(countArr.wwjgd.bad_number_pr);
                        }
                        if(res['dataArr']!=undefined){
                            zxttj(res.dataArr.xAxis,res.dataArr.series);
                        }
                        if(res['list']!=undefined){
                            var html = '';
                            $(res.list).each(function (k,v) {
                                html += '<tr><td>'+v.purchase_code+'</td><td>'+v.need_number+'</td><td>'+v.number+'</td><td>'+v.number_pr+'%</td><td>'+v.bad_number_pr+'%</td></tr>';
                            });
                            $('#orderList').html(html);
                        }
                        if(res['lists']!=undefined){
                            var html = '';
                            $(res.lists).each(function (k,v) {
                                var ks = k-(-1);
                                html += '<tr><td><div class="sort_box"><span class="sort_number">'+ks+'</span></div></td><td>'+v.goods_name+'</td><td>'+v.need_number+'</td><td>'+v.number+'</td></tr>';
                            });
                            $('#phList').html(html);
                        }
                    }
                });
            }

            setInterval (function() {
                getChart(1);
            }, 10000);  //反复执行函数
        },
        stockworing: function () {

            layui.use(['table','upload'], function(){
                var table = layui.table;

                var storesList = Config.storesList;
                var stores = xmSelect.render({
                    el: '#stores',
                    language: 'zn',
                    tips: __('Warehouse'),
                    data: storesList
                });

                var goodsList = Config.goodsList;
                var goodstype = xmSelect.render({
                    el: '#goods',
                    language: 'zn',
                    tips: __('Product classification'),
                    data: goodsList
                });

                table.render({
                    elem: '#table'
                    ,url:'kuyou/datainfo/stockworing'
                    ,parseData: function(res){ //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "msg": '', //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.rows //解析数据列表
                        };
                    }
                    ,toolbar: '#thisToolbar' //开启头部工具栏，并为其绑定左侧模板
                    ,cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    ,cols: [[
                        {field: 'goods_type_id', title: __(__('Product classification')),templet: function (d) {
                                if(d.goodstype.supplier_type_name!=undefined){
                                    return d.goodstype.supplier_type_name;
                                }else{
                                    return '';
                                }
                            }},
                        {field: 'goods_code', title: __(__('Product Code'))},
                        {field: 'goods_name', title: __(__('Product Name'))},
                        {field: 'goods_barcode', title: __(__('Product barcode'))},
                        {field: 'goods_image', title: __(__('Product images')), operate: false,templet: function (d) {
                                return "<a href='javascript:;'><img src="+d.goods_image+"></a>";
                            }},
                        {field: 'unit', title: __(__('Company')),templet: function (d) {
                                if(d.more_unit==1){
                                    return d.unitconversion;
                                }
                                if(d.more_unit==2){
                                    return d.unit.name;
                                }
                            }},
                        {field: 'stores', title: __(__('Warehouse')),templet: function (d) {
                                if(d.stores.name!=undefined){
                                    return d.stores.name;
                                }else{
                                    return '';
                                }
                            }},
                        {field: 'min_stock', title: __(__('Minimum inventory'))},
                        {field: 'max_stock', title: __(__('Maximum inventory'))},
                        {field: 'stock', title: __(__('Current inventory'))},
                    ]]
                });

                //头工具栏事件
                table.on('toolbar(table)', function(obj){
                    switch(obj.event){
                        case 'refresh':
                            table.reload('table', []);
                            break;
                    }
                });
                //搜索事件
                $('#search').on('click', function () {
                    table.reload('table', {
                        where: {
                            filter:JSON.stringify(getSearch()),
                            op:JSON.stringify(getOp()),
                        }
                        ,page: {
                            curr: 1
                        }
                    });
                });
                function getSearch() {
                    var search = {};

                    var storesArr = stores.getValue();
                    var stores_id = '';
                    if(storesArr.length>0){
                        $(storesArr).each(function (k,v) {
                            if(stores_id===''){
                                stores_id += v.value;
                            }else{
                                stores_id += ','+v.value;
                            }
                        })
                    }
                    search.stores_id = stores_id;

                    var typeArr = goodstype.getValue();
                    var type_id = '';
                    if(typeArr.length>0){
                        $(typeArr).each(function (k,v) {
                            if(type_id===''){
                                type_id += v.value;
                            }else{
                                type_id += ','+v.value;
                            }
                        })
                    }
                    search.type_id = type_id;

                    var goods_code = $('#goods_code').val();
                    if(goods_code!=''){
                        search.goods_code = goods_code;
                    }
                    var goods_name = $('#goods_name').val();
                    if(goods_name!=''){
                        search.goods_name = goods_name;
                    }
                    return search;
                }
                function getOp() {
                    var op = {};
                    op.goods_code = 'LIKE';
                    op.goods_name = 'LIKE';
                    return op;
                }
            });
        },
    };

    return Controller;
});
